home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / Dave Mark / Mac C Primer 1 (SC++7) / 4.3 - EventTrigger / EventTrigger.c next >
Encoding:
C/C++ Source or Header  |  1994-04-27  |  2.0 KB  |  99 lines  |  [TEXT/KAHL]

  1. /********************************************************/
  2. /*                                                        */
  3. /*  EventTrigger Code from Chapter Four of                 */
  4. /*                                                        */
  5. /*    ** The Macintosh C Programming Primer, 2nd Ed. **    */
  6. /*                                                      */
  7. /*    Copyright 1992, Dave Mark and Cartwright Reed       */
  8. /*                                                        */
  9. /*  This program demonstrates specific Mac programming    */
  10. /*    techniques.                                            */
  11. /*                                                        */
  12. /********************************************************/
  13.  
  14. #include <AppleEvents.h>
  15. #include <GestaltEqu.h>
  16.  
  17. #define kGestaltMask    1L
  18.  
  19. /***************/
  20. /*  Functions  */
  21. /***************/
  22.  
  23. void    ToolBoxInit( void );
  24. void    EventsInit( void );
  25. void    SendEvent( AEEventID theAEEventID );
  26.  
  27.  
  28. /******************************** main *********/
  29.  
  30. void    main( void )
  31. {
  32.     ToolBoxInit();
  33.     EventsInit();
  34.     
  35.     SendEvent( kAEOpenApplication );
  36.     SendEvent( kAEOpenDocuments );
  37.     SendEvent( kAEPrintDocuments );
  38.     SendEvent( kAEQuitApplication );
  39. }
  40.  
  41.  
  42. /*********************************** ToolBoxInit */
  43.  
  44. void    ToolBoxInit( void )
  45. {
  46.     InitGraf( &qd.thePort );
  47.     InitFonts();
  48.     InitWindows();
  49.     InitMenus();
  50.     TEInit();
  51.     InitDialogs( 0L );
  52.     InitCursor();
  53. }
  54.  
  55.  
  56. /*********************************** EventsInit */
  57.  
  58. void    EventsInit( void )
  59. {
  60.     long    feature;
  61.     OSErr    err;
  62.     
  63.     err = Gestalt( gestaltAppleEventsAttr, &feature );
  64.     
  65.     if ( err != noErr )
  66.     {
  67.         SysBeep( 10 );    /*  Error calling Gestalt!!!  */
  68.         ExitToShell();
  69.     }
  70.     
  71.     if ( !( feature & ( kGestaltMask << gestaltAppleEventsPresent ) ) )
  72.     {
  73.         SysBeep( 10 );    /*  AppleEvents not supported!!!  */
  74.         ExitToShell();
  75.     }
  76.     
  77. }
  78.  
  79.  
  80. /******************************** SendEvent *********/
  81.  
  82. void    SendEvent( AEEventID theAEEventID )
  83. {
  84.     OSErr            err;
  85.     AEAddressDesc    address;
  86.     OSType            appSig;
  87.     AppleEvent        appleEvent, reply;
  88.     
  89.     appSig = 'Prmr';
  90.     
  91.     err = AECreateDesc( typeApplSignature, (Ptr)(&appSig),
  92.                 (Size)sizeof( appSig ), &address );
  93.     
  94.     err = AECreateAppleEvent( kCoreEventClass, theAEEventID, &address,
  95.             kAutoGenerateReturnID, 1L, &appleEvent );
  96.             
  97.     err = AESend( &appleEvent, &reply, kAENoReply + kAECanInteract,
  98.             kAENormalPriority, kAEDefaultTimeout, nil, nil );
  99. }